package com.sunnada.edu.business.setProcess.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sunnada.edu.business.setProcess.service.ProcessMethods;
import com.sunnada.edu.business.setProcess.service.ProcessService;
import com.sunnada.edu.system.pub.common.BasicController;
import com.sunnada.edu.system.pub.common.Tree;
import com.sunnada.edu.system.pub.common.TreeMethods;
import com.sunnada.edu.system.pub.dao.Page;
import com.sunnada.edu.system.pub.service.PubMethods;
import com.sunnada.edu.system.pub.util.Utils;

/***
 * explain 模块控制类 
 * @author chs 2015-5-12
 * version 1.0
 */
@Controller
@RequestMapping("/processController")
public class ProcessController extends BasicController{
	@Resource
	ProcessService processService;
	
	/**首页跳转*/
	@RequestMapping("/smartHome")
	public String smartHome(HttpServletRequest request) {
		request.setAttribute("map", ProcessMethods.getStatistics());
		
		
		//request.setAttribute("list", ProcessMethods.getProjectStatistics());
		return "smart-home";
	}
	
	/** 班组查询 */
	@RequestMapping("/smartHomeSearch")
	public void groupSearch(HttpServletRequest request,
			HttpServletResponse response) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		params.put("SUNNADA_PAGE_SIZE",
				request.getParameter("SUNNADA_PAGE_SIZE"));
		Page page = new Page();
		page.setRowCount(ProcessMethods.getProjectStatisticsCount());
		page.setPageMap(request, page, params);
		List<?> groupList = ProcessMethods.getProjectStatistics(params);
		JSONObject json = new JSONObject();
		json.put("list", groupList);
		json.put("params", params);
		printInfo(response, json);
	}
	
	/**跳转审批详情页*/
	@RequestMapping("/goDetailPage")
	public String goDetailPage(HttpServletRequest request) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		request.setAttribute("recId", params.get("recId"));
		request.setAttribute("auditId", params.get("auditId"));
		String goDetailPage = processService.getDetailPage(params);
		return goDetailPage;
	}
	
	/**流程首页*/
	@RequestMapping("/process")
	public String process(HttpServletRequest request) { 
		String processId=request.getParameter("moduleId");
		request.setAttribute("pathValue", PubMethods.getPathValue(processId));
		return "business/setProcess/setProcess";
	}
	/**查询审核流程的情况*/
	@RequestMapping("/selectProcessInfo")
	public void processSearch(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		Page page = new Page(); 
		page.setRowCount(processService.getProcessInfoCots(params));
		page.setPageMap(request, page, params);
		List<?> list = processService.findProcessInfo(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		json.put("params", params); 
		printInfo(response,json);
	}
	
	/*
	 * 流程列表查询
	 */
	@RequestMapping("/getProcessList")
	public void getProcessList(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		List<?> list = processService.getProcessList(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/*
	 * 审批流程查询
	 */
	@RequestMapping("/getProcessInfo")
	public void getProcessInfo(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		List<?> list = processService.getProcessInfo(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/**流程首页*/
	@RequestMapping("/pageProcessPerson")
	public String pageProcessPerson(HttpServletRequest request) { 
		String temp = request.getParameter("temp");
		request.setAttribute("temp", temp);
		return "business/setProcess/processPerson";
	}
	
	/*
	 * 获取审核人员
	 */
	@RequestMapping("/getProcessPerson")
	public void getProcessPerson(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		Page page = new Page(); 
		page.setRowCount(processService.getProcessPersonCots(params));
		page.setPageMap(request, page, params);
		List<?> list = processService.getProcessPerson(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		json.put("params", params); 
		printInfo(response,json);
	}
	
	/**流程添加页面*/
	@RequestMapping("/processAdd")
	public String processAdd(HttpServletRequest request) { 
		return "business/customerprocess/process_add";
	}
	/**流程修改页面*/
	@RequestMapping("/processUpdate")
	public String processUpdate(HttpServletRequest request) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		Map process = processService.getProcessByRecId(params);
		request.setAttribute("process", process);
		return "business/customerprocess/process_update";
	}
	
	/**流程保存功能 */
	@RequestMapping("/saveProcess")
	public void saveProcess(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, Process.class, params);
		msg = processService.processAdd(params);
		printInfo(response,msg);
	}
	/**流程删除功能*/
	@RequestMapping("/processDelete")
	public void processDelete(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		String processId = request.getParameter("processId");
		params.put("processId",processId);
		msg = processService.processDel(params);		
		printInfo(response,msg);
	}
	/**流程员工驳回功能*/
	@RequestMapping("/reject")
	public void reject(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		msg = processService.reject(params);		
		printInfo(response,msg);
	}

	/**根据id获取申请单流程的基本情况*/
	@RequestMapping("/getProcessConditionByrecid")
	public void getProcessConditionByrecid(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		List<?> list = processService.getProcessConditionByrecid(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	/*
	 * 获取待处理流程数
	 */
	@RequestMapping("/getNoDealWithNumber")
	public void getNoDealWithNumber(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		Map map = processService.getNoDealWithNumber(params);
		JSONObject json = new JSONObject();		
		json.put("map", map);
		printInfo(response,json);
	}
}
